package com.shop.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.entity.SupplierCategory;
import com.shop.mapper.SupplierCategoryMapper;
import com.shop.model.PageParam;
import com.shop.model.vo.Rsp;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (SupplierCategory)表服务接口
 *.
 * @author makejava
 * @since 2020-11-21 10:12:50
 */
@Service
@AllArgsConstructor
public class SupplierCategoryService {
    private final SupplierCategoryMapper supplierCategoryMapper;



    /**
     * @author Clh
     * @description 开启分页 模糊查询
     * @date  2020/11/25 19:55
     * @param pageParam 分页插件
     * @return com.github.pagehelper.PageInfo
    **/
    public PageInfo searchSomeByPage(PageParam<SupplierCategory> pageParam, Integer supplierId) {
            //开启分页
            PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
            //排序
            for (int i = 0; i < pageParam.getOrderParams().length; i++) {
                PageHelper.orderBy(pageParam.getOrderParams()[i]);
            }
            List<SupplierCategory> supplierCategoryList = supplierCategoryMapper.searchSomeByPage(pageParam.getSuperSearchKeyWord(),supplierId);
            PageInfo<SupplierCategory> pageInfo = new PageInfo(supplierCategoryList);
            return pageInfo;
        }


    /**
     * 修改商品
     * @param
     * @return
     */
    public Integer updateCategoryName(SupplierCategory supplierCategory,Integer userId) {
        supplierCategory.setUpdateUserId(userId);
        return supplierCategoryMapper.update(supplierCategory);
    }

    /**
     * 新增商品
     * @param
     * @return
     */
    public int insertCategory(SupplierCategory supplierCategory,Integer supplierId) {
        supplierCategory.setSupplierId(supplierId);
        return supplierCategoryMapper.insert(supplierCategory);
    }

    /**
     * 删除商品
     * @param id
     * @return
     */
    public int delCategory(Integer id) {
        return supplierCategoryMapper.deleteById(id);
    }
    /**
     * @author Clh
     * @description 动态添加
     * @date  2020/11/25 19:34
     * @param
     * @param
     * @return com.shop.model.vo.Rsp
    **/
    public Rsp insertSelective(SupplierCategory supplierCategory, Integer supplierId, Integer userId){
        supplierCategory.setSupplierId(supplierId);
        supplierCategory.setCreateUserId(userId);
        Integer insertSelective = supplierCategoryMapper.insertSelective(supplierCategory);
        return insertSelective>0?Rsp.success(null).msg("添加成功"):Rsp.fail().msg("添加失败");
    }
    /**
     * 查询商品列表
     * @return
     */
    public List<SupplierCategory> getCategoryList(Integer supplierId) {
        return supplierCategoryMapper.getCategoryList(supplierId);
    }
}
